package com.woniu.controller;

import com.woniu.pojo.PageBean;
import com.woniu.pojo.Permission;
import com.woniu.pojo.Role;
import com.woniu.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    @RequestMapping("list")
    public String list(){
        return "permission/list";
    }
    @RequestMapping("listDo")
    @ResponseBody
    public List<Permission> listDo(){
        List<Permission> rootList = new ArrayList<>();
        rootList = permissionService.getPermissions();
        return rootList;
    }
    @RequestMapping("permissionSaveDo")
    @ResponseBody
    public Map<String,Object> permissionSaveDo(Permission permission){
        Map<String,Object> resultMap = new HashMap<>();
        try{
            permissionService.save(permission);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
        return resultMap;
    }
}
